#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <bitset>
#include <utility>
using namespace std;

#define mm(a, n) memset(a, n, sizeof a)
#define mk(a, b) make_pair(a, b)

const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

const int N = 1010;

int n;
int preorder[N], inorder[N];
int postorder[N], idx;

bool build(int pl, int pr, int il, int ir, int type) {
    // 没有元素 一定能重建成功
    if (il > ir) return true;

    int root = preorder[pl];

    int k;
    if (!type) {
        for (k = il; k <= ir; k ++ ) 
            if (inorder[k] == root) break;
        if (k > ir) return false;
    } else {
        for (k = ir; k >= il; k -- ) 
            if (inorder[k] == root) break;
        if (k < il) return false;
    }

    bool res = true;
    // 判断左子树能否构建
    if (!build(pl + 1, pl + 1 + (k - 1 - il), il, k - 1, type)) res = false;
    if (!build(pl + 1 + (k - 1 - il) + 1, pr, k + 1, ir, type)) res = false;

    postorder[idx ++ ] = root;
    return res;
}


// 二叉搜索树
inline void solution() {
    cin >> n;
    for (int i = 0; i < n; i ++ ) {
        cin >> preorder[i];
        inorder[i] = preorder[i];
    }

    sort(inorder, inorder + n);

    if (build(0, n - 1, 0, n - 1, 0)) {
        cout << "YES" << endl;
        cout << postorder[0];
        for (int i = 1; i < n; i ++ ) 
            cout << " " << postorder[i];
        cout << endl;
    } else {
        reverse(inorder, inorder + n);
        idx = 0;
        if (build(0, n - 1, 0, n - 1, 1)) {
            cout << "YES" << endl;
            cout << postorder[0];
            for (int i = 1; i < n; i ++ ) 
                cout << " " << postorder[i];
            cout << endl;
        } else 
            puts("NO");
    }
    return ;
}

int main() {
    freopen("input.txt", "r", stdin);
    quickread();
    solution();
    return 0;
}